<?php
header("Content-Type: text/html; charset=utf-8\n");
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/

	defined('_JEXEC') or die('Retricted Access');	
	JHTML::_('behavior.tooltip');
	if (! class_exists ( 'JAStack' )&&! class_exists ( 'SmartTrim' ))
	require_once(JPATH_SITE.DS.'components'.DS.'com_jajobboard'.DS.'helper'.DS.'jahelper.php');
	global $jbconfig, $option;  

	if(!isset($this->fieldlist)) $this->fieldlist = array();
	
	$Itemid = JRequest::getInt('Itemid');
	if(!$Itemid){
		$Itemid	= get_Itemid(array('option'=>'com_jajobboard', 'view'=>'jajobs', 'layout'=>'jalist'));
	}		
	
	$is_jobsearch = JRequest::getVar('is_jobfilter');
	$user = JFactory::getUser();?>
	<?php if(!JRequest::getInt('ajax', 0) || JRequest::getVar('layout')!='jalist'){?>
	<script type="text/javascript">
	/* <![CDATA[ */	
		var siteurl = '<?php echo JURI::root(); ?>';
	 	var Itemid = '<?php echo $Itemid?>';   
	 	var table_name = 'ja_jobs';
	 	
	 	if($type(number_items_search))
	 		var number_items_search	= 20;
	 	
	 	var makeSelectSave = '<?php echo JText::_("Please make a selection from the list to save"); ?>';
	 	var makeSelectView = '<?php echo JText::_("Please make a selection from the list to view detail"); ?>';
	 	var makeSelectDelete = '<?php echo JText::_("Please make a selection from the list to delete"); ?>';
	/* ]]> */
	</script>
	<?php 
		$uid = JRequest::getVar('uid');
		if (isset($this->profile)&&$uid) {
			 
	?>
	<h3>
	<?php echo JText::_('Job posting by'). ' ' . $this->profile->company;?>
	</h3>
	<?php
		}
	?>
	<?php } if(!JRequest::getInt('ajax', 0) ){?>
	<div id="jobboard-content">
	<?php }?>			
	<?php 
		if (isset($this->pagination)){
			$total_items = $this->pagination->total;
		}elseif(isset($this->all_items)){ 			
			$total_items = count($this->all_items);
		}else{ 
			$total_items = 0;
		}
		$this->total_items = $total_items;
		
		if (isset($is_jobsearch)){
			$is_filter = false;
			$text = JText::_('Your search');
			$jobsearch_author = JRequest::getVar('job_author');
			$jobsearch_keyword = JRequest::getVar('filter_keyword');
			$jobsearch_cat = str_replace(array(',', "--"), array(', ', "&"), JRequest::getVar('cat_id'));
			$jobsearch_location = str_replace(array(',', "--"), array(', ', "&"), JRequest::getVar('location_id'));
			$jobsearch_salary_from = JRequest::getVar('filter_salary_from');
			$jobsearch_salary_to = JRequest::getVar('filter_salary_to');
			$jobsearch_job_type = JRequest::getVar('job_type');
			$jobsearch_posted_date = JRequest::getVar('posted_date');		
			
			if(is_array($jobsearch_cat)) $jobsearch_cat = implode(', ', $jobsearch_cat);
			if(is_array($jobsearch_location)) $jobsearch_location = implode(', ', $jobsearch_location);
			
			require_once dirname(__FILE__).DS.'jalist_search_result_msg.php';
		}		
		elseif (JRequest::getVar('dosearch'))
		{
			$text = sprintf( JText::_("Your filter return %s job(s)"), $this->total_items) ;
				echo "<span class=\"ja-jobsearch-result\">".$text."</span>";
		}
		
		?>
		<form name="adminForm" action="<?php echo JRoute::_('index.php?option=com_jajobboard&view=jajobs&Itemid='.$Itemid)?>" method="post">    
		
			<!--	BEGIN: All Job List-->
			<?php
			jimport('joomla.filesystem.file');
			$theme = JRequest::getVar('theme');
			if (!$theme)	$theme = $jbconfig['general']->get('theme', 'default');
						
			if(!count($this->all_items)>0){
				echo JText::_('No jobs are found!');
			} 
			elseif( (isset($this->fieldlist) && count($this->fieldlist)>0) ){
				$path_themes = dirname(__FILE__).DS.'themes'.DS.$theme.DS.'jalist-item.php';
				if(JFile::exists($path_themes)){
					if(file_exists(dirname(__FILE__).DS.'themes'.DS.$theme.DS.'style.css')){
				    	JHTML::stylesheet('style.css', "components/com_jajobboard/views/jajobs/tmpl/themes/$theme/");
				    }
				    include $path_themes;
				}			
				elseif(JFile::exists(dirname(__FILE__).DS.'themes'.DS.'default'.DS.'jalist-item.php')){
					if(file_exists(dirname(__FILE__).DS.'themes'.DS.'default'.DS.'style.css')){
				    	JHTML::stylesheet('style.css', "components/com_jajobboard/views/jajobs/tmpl/themes/default/");
				    }	
					include dirname(__FILE__).DS.'themes'.DS.'default'.DS.'jalist-item.php';
				}
				elseif(JFile::exists(JPATH_FILE.DS.'components'.DS.'com_jajobboard'.DS.'views'.DS.'jajobs'.DS.'tmpl'.DS.'themes'.DS.'default'.DS.'jalist-item.php')){
					if(file_exists(dirname(__FILE__).DS.'themes'.DS.'default'.DS.'style.css')){
				    	JHTML::stylesheet('style.css', "components/com_jajobboard/views/jajobs/tmpl/themes/default/");
				    }	
					include JPATH_FILE.DS.'components'.DS.'com_jajobboard'.DS.'views'.DS.'jajobs'.DS.'tmpl'.DS.'themes'.DS.'default'.DS.'jalist-item.php';
				}
			}
			
			
			?>
			<!--	END: All Job List-->											
			
			<?php 
			$cid = JRequest::getVar('cid');	
			if (isset($cid[0]))	$cid = $cid[0];
			?>
			
			<?php if ($is_jobsearch) {?>	
			
			<input type="hidden" name="is_jobfilter" value="<?php echo $is_jobsearch ?>" />
			<input type="hidden" name="location_id" value="<?php echo str_replace(', ',',',$jobsearch_location); ?>" />
			<input type="hidden" name="cat_id" value="<?php echo str_replace(', ',',',$jobsearch_cat); ?>" />
			<input type="hidden" name="job_type" value="<?php echo $jobsearch_job_type; ?>" />
			<input type="hidden" name="layout" value="filter_job_list" />
			<?php } else{?>									
			<input type="hidden" name="layout" value="<?php echo JRequest::getVar('layout', 'jalist')?>" />
			<?php }?>
			
			<input type="hidden" id="cids" name="cids[]" value="<?php echo $cid; ?>" />						
		 	<input type="hidden" name="boxchecked" id="boxcheckedadminForm" value="0" />
		 	<input type="hidden" name="boxcheck" value="0" />
		 	<input type="hidden" name="field" value="" />
		 	<input type="hidden" name="option" value="com_jajobboard" />
			<input type="hidden" name="view" value="jajobs" />
			<input type="hidden" name="layout" value="jalist" />
		    <input type="hidden" name="task" value="" />
		    <input type="hidden" name="pre_layout" value="jalist" />
		    <input type="hidden" id="total_item" name="total_item" value="<?php echo count($this->all_items); ?>" />
		    <?php $filter_order = JRequest::getVar('filter_order', $jbconfig['posts']->get('filter_order')); ?>
		    <?php if(strpos($filter_order, '.')<0) $filter_order = 'a.'.$filter_order?>
			<?php $filter_order_dir = JRequest::getVar('filter_order_Dir', $jbconfig['posts']->get('filter_order_Dir'));?>
			<input type="hidden" name="filter_order" id="filter_order" value="<?php echo $filter_order ?>" />
			<input type="hidden" name="filter_order_Dir" id="filter_order_Dir" value="<?php echo $filter_order_dir; ?>" />
			<input type="hidden" name="Itemid" value="<?php echo $Itemid;?>" />
		
		 </form>
	<?php if(!JRequest::getInt('ajax', 0)){?>	
	</div>
	<?php }?>
	
	<?php if(!JRequest::getInt('ajax', 0)){?>	
	<script type="text/javascript">
	/* <![CDATA[ */
		var itemid = '<?php echo JRequest::getVar('Itemid'); ?>';
		if(typeof( window[ 'filter' ] )== 'undifined'){
			var filter = new Array(0);
			var parent = new Array(0);
		}	
		
	/* ]]> */
	</script>
	<?php }?>